package com.study.thymeleaf;

import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templatemode.TemplateMode;
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;

import java.util.Arrays;

public class xxx {
    public static void main(String[] args) {
        // 创建一个模板解析器
        ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver();
        resolver.setPrefix("templates/");
        resolver.setSuffix(".java");
        resolver.setTemplateMode(TemplateMode.TEXT);

        // 创建一个模板引擎
        TemplateEngine engine = new TemplateEngine();
        engine.setTemplateResolver(resolver);

        // 创建一个上下文对象
        Context context = new Context();
        context.setVariable("name", "World");
        context.setVariable("tableName", "dept");
        context.setVariable("items", Arrays.asList("dname","local"));

        // 渲染模板
        String html = engine.process("hello", context);
        System.out.println(html);

    }
}
